/*
ID: guoxu1
PROG: preface
LANG: C++
*/
#include <fstream>
#include <string>
using namespace std;

const char* patterns[] = { "", "A", "AA", "AAA", "AB", "B", "BA", "BAA", "BAAA", "AC" };
const char* chars[] = { "ABC", "CDE", "EFG", "G  " };
char trans[] = { 'I', 'V', 'X', 'L', 'C', 'D', 'M' };

string dec2roman( int n )
{
  string r;
  int i = 0;
  while( n > 0 )
  {
    int t = n % 10;
    n = n / 10;

    string p = patterns[t];
    for( string::iterator it = p.begin(); it != p.end(); it++ )
    {
      *it = chars[i][*it - 'A'];
    }
    r = p + r;
    i++;
  }
  return r;
}

#define cin fin
#define cout fout

int main()
{
  ifstream fin( "preface.in" );
  ofstream fout( "preface.out" );

  int n = 0;
  cin >> n;
  string total;
  for( int i = 1; i <= n; i++ )
  {
    total += dec2roman(i);
  }

  int count[7] = {0};
  for( string::const_iterator it = total.begin(); it != total.end(); it++ )
  {
    int off = *it - 'A';
    if( off < 0 || off >= 7 ) continue;
    count[off]++;
  }

  for( int i = 0; i < 7; i++ )
  {
    if( count[i] == 0 ) continue;
    cout << trans[i] << " " << count[i] << endl;
  }
  
  return 0;
}
